package com.wowangz.cms.systemmanage.province.service;

import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;
import com.wowangz.cms.systemmanage.province.pojo.Province;

public class ProvinceService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(ProvinceService.class);

	/*

	public void delete(String ids) throws Exception {
		if (StringUtils.isEmpty(ids)) {
			return;
		}
		String[] temIds = ids.split(",");
		SqlSessionContainer sessionContainer = new SqlSessionContainer();
		SqlSession sqlSession = (SqlSession) sessionContainer.getSqlSession();

		for (String id : temIds) {
			sqlSession.delete("Currency.deleteCurrency", id);
		}
	}

	*/
	
	/*public void updateAllCurrencyposition(Long currencyposition){
		SqlSessionContainer sessionContainer = new SqlSessionContainer();
		SqlSession sqlSession = (SqlSession) sessionContainer.getSqlSession();
		sqlSession.update("Currency.updateAllCurrencyposition", currencyposition);
	}

	

	public List<Province> query(Province province) throws Exception {
		SqlSessionContainer sessionContainer = new SqlSessionContainer();
		SqlSession sqlSession = (SqlSession) sessionContainer.getSqlSession();
		List<Province> list = sqlSession.selectList("Currency.queryCurrency");
		return list;

	}
	*/
	
	/**
	 * 新增省信息
	 * @param province
	 * @throws Exception
	 */
	public void add(Province province) throws ServiceException {
		try {
			this.getSqlSession().insert("Province.insertProvince", province);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}
	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		Long countNum = null;
		try {
			countNum = this.getSqlSession().selectOne("Province.queryProvinceCount", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return countNum;
	}
	
	/**
	 * 查询所有的省信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public List<Province> queryProvince() throws ServiceException {
		List<Province> list = null;
		try {
			list = this.getSqlSession().selectList("Province.queryProvince");
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return list;
	}
	

	/**
	 * 查询记录集合
	 * 
	 * @param map
	 * @return
	 */
	public List<Province> findResultList(HashMap<String, Object> map) throws ServiceException {
		List<Province> list = null;
		try {
			list = this.getSqlSession().selectList("Province.queryProvincePage", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return list;
	}
	
	/**
	 * 验证信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public boolean validationProvince(HashMap<String, Object> map) throws ServiceException {
		Long countNum = null;
		try {
			countNum = this.getSqlSession().selectOne("Province.validationProvince", map);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		if(countNum != 0){
			return false;
		}else{
			return true;
		}
	}
	
	public Province findProvinceById(String id) throws ServiceException {
		Province province = null;
		try {
			province = this.getSqlSession().selectOne("Province.findProvinceById", id);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
		return province;
	}
	
	public void update(Province province) throws ServiceException {
		try {
			this.getSqlSession().update("Province.updateProvince", province);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}

}
